#include "loginpage.h"
#include "ui_loginpage.h"
#include "netmain.h"
#include <QMessageBox>
#include "mainpage.h"

LoginPage *LoginPage::obj = nullptr;

LoginPage::LoginPage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginPage)
{
    ui->setupUi(this);
    connect(NetMain::getObject(), &NetMain::userLoginRe,
            this, &LoginPage::userLoginReSlot);
}

LoginPage::~LoginPage()
{
    delete ui;
}

LoginPage *LoginPage::getObject()
{
    if(obj == nullptr)
        obj = new LoginPage;
    return obj;
}

void LoginPage::on_btn_login_clicked()
{
    NetMain::getObject()->userLogin(
                ui->le_username->text(),
                ui->le_password->text()
                );
}

void LoginPage::userLoginReSlot(bool re)
{
    if(re)
    {
        this->hide();
        MainPage::getObject()->show();
    }
    else
    {
        QMessageBox::warning(this, "警告", "用户名或密码错误");
    }
}

